package cn.iocoder.yudao.module.of.service.schedulepart;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.of.controller.admin.schedulepart.vo.*;
import cn.iocoder.yudao.module.of.dal.dataobject.schedulepart.SchedulePartDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.of.dal.mysql.schedulepart.SchedulePartMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.of.enums.ErrorCodeConstants.*;

/**
 * 日程中心参与者 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class SchedulePartServiceImpl implements SchedulePartService {

    @Resource
    private SchedulePartMapper schedulePartMapper;

    @Override
    public Long createSchedulePart(SchedulePartSaveReqVO createReqVO) {
        // 插入
        SchedulePartDO schedulePart = BeanUtils.toBean(createReqVO, SchedulePartDO.class);
        schedulePartMapper.insert(schedulePart);
        // 返回
        return schedulePart.getId();
    }

    @Override
    public void updateSchedulePart(SchedulePartSaveReqVO updateReqVO) {
        // 校验存在
        validateSchedulePartExists(updateReqVO.getId());
        // 更新
        SchedulePartDO updateObj = BeanUtils.toBean(updateReqVO, SchedulePartDO.class);
        schedulePartMapper.updateById(updateObj);
    }

    @Override
    public void deleteSchedulePart(Long id) {
        // 校验存在
        validateSchedulePartExists(id);
        // 删除
        schedulePartMapper.deleteById(id);
    }

    private void validateSchedulePartExists(Long id) {
        if (schedulePartMapper.selectById(id) == null) {
            throw exception(USER_REMIND_SETUP_NOT_EXISTS);
        }
    }

    @Override
    public SchedulePartDO getSchedulePart(Long id) {
        return schedulePartMapper.selectById(id);
    }

    @Override
    public PageResult<SchedulePartDO> getSchedulePartPage(SchedulePartPageReqVO pageReqVO) {
        return schedulePartMapper.selectPage(pageReqVO);
    }

}